package edu.sandau.b230111.b23011125.Service.Impl;

import edu.sandau.b230111.b23011125.Global.GlobalEnum;
import edu.sandau.b230111.b23011125.Model.SubmitRecord;
import edu.sandau.b230111.b23011125.Repository.RecordRepository;
import edu.sandau.b230111.b23011125.Service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class RecordServiceImpl implements RecordService {
    @Autowired
    private RecordRepository recordRepository;
    @Override
    public GlobalEnum.OperateResult saveRecord(SubmitRecord record) {
        recordRepository.save(record);
        return GlobalEnum.OperateResult.SUCC;
    }

    @Override
    public Page<SubmitRecord> queryRecordByProblemId(String problemid, Integer pageNum, Integer pageSize) {
        Pageable page = PageRequest.of(pageNum,pageSize);
        Page<SubmitRecord> ans = recordRepository.findByProblemid(problemid,page);
        return ans;
    }

    @Override
    public Page<SubmitRecord> queryAllRecord(Integer pageNum, Integer pageSize) {
        Pageable page = PageRequest.of(pageNum,pageSize);
        Page<SubmitRecord> ans = recordRepository.findAll(page);
        return ans;
    }
}
